package ru.agiledev.akb.server.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by a.kirillov
 * Date: 5/10/11 Time: 8:11 PM
 */
public class HashUtils{

    public static String createSHA256(String source) throws NoSuchAlgorithmException {

        MessageDigest md = null;
            md = MessageDigest.getInstance("SHA-256");

        md.update(source.getBytes());

        byte byteData[] = md.digest();

        StringBuffer hexString = new StringBuffer();
        for (int i=0;i<byteData.length;i++) {
            String hex=Integer.toHexString(0xff & byteData[i]);
            if(hex.length()==1) hexString.append('0');
            hexString.append(hex);
        }
        return hexString.toString();
    }
}
